//
// Created by francklinson on 2021/10/22 AT 22:19.
//
#include <iostream>
#include <thread>

static bool s_Finished = false;

void doWork() {
    using namespace std::literals::chrono_literals;
    std::cout << "Started thread id = " << std::this_thread::get_id() << std::endl;
    while (!s_Finished) {
        std::cout << "working..." << std::endl;
        std::this_thread::sleep_for(1s); // 睡眠1s
    }
    std::cout << "work finish!" << std::endl;

}

int main() {
    std::thread worker(doWork);
    std::cin.get();
    s_Finished = true; // 主线程中 获取到get，将标识符变为true，影响子线程
    worker.join(); // 等待worker结束
    std::cout << "back to main thread!" << std::endl;
    std::cout << "Started thread id = " << std::this_thread::get_id() << std::endl;
    std::cin.get();

}

